<template>
  <div :class="content">
    <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
      <!-- 1 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="编号">
            <el-input v-model="form.number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="客户名称">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系人">
            <el-input v-model="form.linkman"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 2 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="职位">
            <el-select v-model="form.value1" placeholder="请选择">
              <el-option
                v-for="item in position"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机号码">
            <el-input v-model="form.phonenumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="电子邮箱">
            <el-input v-model="form.email"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 3 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="网址">
            <el-input v-model="form.website"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="所属行业">
            <el-select v-model="form.value2" placeholder="请选择">
              <el-option
                v-for="item in industry"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="录入时间">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date1"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
            <el-col class="line" :span="2">-</el-col>
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date2"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 4 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="最后更新">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date3"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
            <el-col class="line" :span="2">-</el-col>
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date4"
                style="width: 100%"
              ></el-date-picker>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="所在地区">
            <el-cascader
              size="large"
              :options="form.options"
              v-model="form.selectedOptions"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="QQ">
            <el-input v-model="form.QQ"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 5 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="详细地址">
            <el-input v-model="form.address"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="邮编">
            <el-input v-model="form.postcode"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预留字段1">
            <el-input v-model="form.reserved1"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 6 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="预留字段2">
            <el-input v-model="form.reserved2"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预留字段3">
            <el-input v-model="form.reserved3"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预留字段4">
            <el-input v-model="form.reserved4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 7 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="备注">
            <el-input v-model="form.note"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="客户类型">
            <el-select v-model="form.value3" placeholder="请选择">
              <el-option
                v-for="(item, index) in typeArr"
                :key="index"
                :label="item.label"
                :value="item.dic_Name"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="客户级别">
            <el-select v-model="form.value4" placeholder="请选择">
              <el-option
                v-for="item in level"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 8 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="客户来源">
            <el-select v-model="form.value5" placeholder="请选择">
              <el-option
                v-for="(item, index) in originArr"
                :key="index"
                :label="item.label"
                :value="item.dic_Name"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="商品类别">
            <el-select v-model="form.value6" placeholder="请选择">
              <el-option
                v-for="item in goodscategory"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="部门">
            <el-select v-model="form.value7" placeholder="请选择">
              <el-option
                v-for="item in department"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 9 -->
      <el-row>
        <el-col :span="8">
          <el-form-item label="录入者">
            <el-select v-model="form.value8" placeholder="请选择">
              <el-option
                v-for="item in Entry"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="审核中">
            <el-select v-model="form.value9" placeholder="请选择">
              <el-option
                v-for="item in auditing"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="自定义搜索">
            <el-input v-model="form.searching"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 10 -->
      <el-row>
        <el-col :span="16">
          <el-form-item label="其他">
            <div>
              <el-checkbox-group v-model="form.checkboxGroup1">
                <el-checkbox-button
                  v-for="item in form.others"
                  :label="item"
                  :key="item"
                  >{{ item }}</el-checkbox-button
                >
              </el-checkbox-group>
            </div>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 底部按钮 -->
      <el-row :class="btn">
        <el-col>
          <el-button type="primary" @click="submitForm" plain
            >立即搜索</el-button
          >
          <el-button type="warning" @click="resetForm" plain
            >清空条件</el-button
          >
          <el-button type="info" @click="exportForm" plain>导出数据</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template> 

<script>
import { provinceAndCityDataPlus, CodeToText } from "element-china-area-data";
import { mapMutations, mapState } from "vuex";
export default {
  name: "SearchItem",
  data() {
    return {
      form: {
        QQ: "", //qq
        address: "", //详细地址
        postcode: "", //邮编
        reserved1: "", //预留字段1
        reserved2: "", //预留字段2
        reserved3: "", //预留字段3
        reserved4: "", //预留字段4
        note: "", //备注
        number: "", //编号
        name: "", //客户名称
        linkman: "", //联系人
        phonenumber: "", //手机号码
        email: "", //电子邮箱
        website: "", //网址
        searching: "", //自定义搜索
        options: provinceAndCityDataPlus, //所在地区省市
        selectedOptions: "",
        value1: "",
        value2: "",
        value3: "",
        value4: "",
        value5: "",
        value6: "",
        value7: "",
        value8: "",
        value9: "",
        date1: "",
        date2: "",
        date3: "",
        date4: "",
        others: ["有跟单", "有订单", "有合同", "有售后", "有附件"],
        checkboxGroup1: [],
      },
      btn: "btn",
      content: "content",
    };
  },
  props: {
    position: Array, //职位
    industry: Array, //行业
    customertype: Array, //客户类型
    level: Array, //客级别
    source: Array, //客户来源
    goodscategory: Array, //商品来源
    department: Array, //部门
    Entry: Array, //录入者
    auditing: Array, //审核
    typeArr: Array,
    originArr: Array,
  },
  computed: {
    ...mapState("userManage", ["customerType", "customerOrigin"]),
  },
  methods: {
    ...mapMutations(["userManage/fixSearchValArr"]),
    submitForm() {
      this["userManage/fixSearchValArr"](this.form);
    }, //搜索
    resetForm() {
      this.form.QQ = "";
      this.form.address = "";
      this.form.postcode = "";
      this.form.reserved1 = "";
      this.form.reserved2 = "";
      this.form.reserved3 = "";
      this.form.reserved4 = "";
      this.form.note = "";
      this.form.number = "";
      this.form.name = "";
      this.form.linkman = "";
      this.form.phonenumber = "";
      this.form.email = "";
      this.form.website = "";
      this.form.searching = "";
      this.form.selectedOptions = "";
      this.form.value1 = "";
      this.form.value2 = "";
      this.form.value3 = "";
      this.form.value5 = "";
      this.form.value7 = "";
      this.form.value9 = "";
      this.form.date1 = "";
      this.form.date2 = "";
      this.form.date3 = "";
      this.form.date4 = "";
    }, //重置
    exportForm() {
      console.log(this.typeArr, this.originArr);
    }, //导出
    handleChange() {
      //地区选择
      var loc = "";
      for (let i = 0; i < this.selectedOptions.length; i++) {
        loc += CodeToText[this.selectedOptions[i]];
      }
      alert(loc);
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  margin: 20px 0px;
}
.btn {
  text-align: center;
}
</style>